﻿using System;
using System.Collections.Generic;
using System.Text;

namespace Orderr
{
    [Serializable]
    public class Order : IComparable
    {
        public int oid { get; set; }
        public Client client;
        public List<OrderDetails> Details;
        public Order()
        {
            oid = 0;
            client = null;
            Details = new List<OrderDetails>();
        }
        public Order(int OID, Client clien, List<OrderDetails> DeList)
        {
            oid = OID;
            client = clien;
            Details = DeList;
        }
        public int totalPrice
        {
            get
            {
                int Sum = 0; Action<OrderDetails> getSum = (x => Sum += x.good.price * x.nums);
                Details.ForEach(getSum);
                return Sum;
            }
        }
        public int CompareTo(object obj2)
        {
            Order other = obj2 as Order;
            return oid - other.oid;
        }
        public override string ToString()
        {
            string ret = "------------------------------\nOrder id = " + oid + "\nClient : " + client.ToString() + "\ntotal price = " + totalPrice.ToString() + "\nDetails are below:\n";
            foreach (OrderDetails x in Details)
            {
                ret += x.ToString();
            }
            return ret;
        }
        public override bool Equals(object obj)
        {
            Order ob = obj as Order;
            return oid == ob.oid;
        }
        public override int GetHashCode()
        {
            return oid;
        }
    }
}
